<?php
// @formatter:off
/**
 * @file bundlepreview.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-16 23:56:49 +0000 (Sun, 16 Jun 2013) $
 *
 * $Id: bundlepreview.php 73 2013-06-16 23:56:49Z daemonraco@gmail.com $
 * $URL:https://wcomix.googlecode.com/svn/trunk/themes/default/controlers/generics/bundlepreview.php$
 */
// @formatter:on

global $wcThemeAssigns;

$wcThemeAssigns["BP-SCRIPT"] = "/generics/bundlepreview.js";

function wcGetBundlePreviewAssigns(&$item, $css = false, $info = array()) {
	global $wcDefaults;

	$out = array();

	//
	// Basic information.
	$out["BP-ID"] = $item->id();
	$out["BP-NAME"] = $item->name();
	$out["BP-INFO"] = $info;
	$out["BP-PREVIEW"] = $item->preview();
	$out["BP-PREVIEW-SPAN"] = count($info) + 1;
	$out["BP-PREVIEWS"] = $item->previews();

	if($css) {
		$out["BP-CSS"] = $css;
	}

	return $out;
}
function wcGetCollectionPreviewAssigns(WCCollection &$collection, $css = false) {
	global $wcSite;
	global $wcProfile;

	$info = array();
	$info[] = array(
		"what" => "Collections",
		"value" => count($collection->collections())
	);
	$info[] = array(
		"what" => "Comics",
		"value" => $collection->count
	);

	$out = wcGetBundlePreviewAssigns($collection, $css, $info);

	$out["BP-WHAT"] = "collection";
	$out["BP-ACTION"] = WC_ACTION_COLLECTION_SHOW;

	if($wcProfile->allowedTo(WC_PERM_COLLECTION_REMOVE)) {
		$out["BP-REMOVER"] = true;
		$out["BP-REMOVER-ACTION"] = "RemoveCollection('".WC_SERVICE_COLLECTIONS."',{$collection->id},'{$collection->name}')";
	}

	if($wcSite["wiki"]) {
		$out["BP-WIKI"] = true;
		$out["BP-WIKI-URL"] = "{$wcSite["wiki"]}WCCollection:{$collection->name}";
	}

	return $out;
}
function wcGetDirectoryPreviewAssigns(WCDirectory &$directory, $css = false) {
	$info = array();
	$info[] = array(
		"what" => "Comics",
		"value" => $directory->count
	);

	$out = wcGetBundlePreviewAssigns($directory, $css, $info);

	$out["BP-WHAT"] = "directory";
	$out["BP-ACTION"] = WC_ACTION_DIRECTORY_SHOW;

	return $out;
}
function wcGetTagPreviewAssigns(WCTag &$tag, $css = false) {
	global $wcSite;

	$info = array();
	$info[] = array(
		"what" => "Comics",
		"value" => $tag->count
	);

	$out = wcGetBundlePreviewAssigns($tag, $css, $info);

	$out["BP-WHAT"] = "tag";
	$out["BP-ACTION"] = WC_ACTION_TAG_SHOW;

	if($wcSite["wiki"]) {
		$out["BP-WIKI"] = true;
		$out["BP-WIKI-URL"] = "{$wcSite["wiki"]}WCTag:{$tag->name}";
	}

	return $out;
}
function wcGetRulePreviewAssigns(WCRule &$rule, $css = false) {
	global $wcProfile;

	$info = array();
	$info[] = array(
		"what" => "Actions",
		"value" => $rule->count
	);

	if($rule->conflict) {
		$css = ($css ? "{$css} " : "")."MultiItemConflict";
	}

	$out = wcGetBundlePreviewAssigns($rule, $css, $info);

	$out["BP-WHAT"] = "rule";
	$out["BP-ACTION"] = WC_ACTION_RULE_SHOW;

	$out["BP-NO-PREVIEW"] = true;

	if($wcProfile->allowedTo(WC_PERM_RULE_REMOVE)) {
		$out["BP-REMOVER"] = true;
		$out["BP-REMOVER-ACTION"] = "RemoveRule('".WC_SERVICE_RULES."',{$rule->id},'{$rule->name}')";
	}

	return $out;
}
function wcGetRuleActionPreviewAssigns(WCRuleAction &$action, $css = false) {
	global $wcGroup;
	global $wcRule;
	global $wcRuleHooks;
	global $wcProfile;

	$info = array();
	$info[] = array(
		"what" => "Type",
		"value" => $action->type()
	);

	if($action->conflict()) {
		$css = ($css ? "{$css} " : "")."MultiItemConflict";
	}

	$out = wcGetBundlePreviewAssigns($action, $css, $info);

	$out["BP-WHAT"] = "raction";
	// auto-hack
	$out["BP-ACTION"] = WC_ACTION_CANVAS."&saction={$wcRuleHooks[$action->type()]["edit"]}&rule={$wcRule->id()}";

	$out["BP-NO-PREVIEW"] = true;

	if($wcProfile->allowedTo(WC_PERM_RULE_EDIT)) {
		$out["BP-REMOVER"] = true;
		$out["BP-REMOVER-URL"] = "?action=".WC_ACTION_CANVAS."&saction={$wcRuleHooks[$action->type()]["remove"]}&group={$wcGroup->id()}&rule={$wcRule->id()}&raction={$action->id()}";
	}

	return $out;
}
function wcGetUserPreviewAssigns(WCUser &$user, $css = false) {
	global $wcProfile;
	global $wcUser;

	$info = array();

	$info[] = array(
		"what" => "Name",
		"value" => $user->data()->fullname
	);

	$out = wcGetBundlePreviewAssigns($user, $css, $info);

	$out["BP-WHAT"] = "user";
	$out["BP-ACTION"] = ($wcProfile->granted(WC_PERM_USER_EDIT) || ($wcUser && $wcUser->id() == $user->id() && $wcProfile->granted(WC_PERM_USER_SELF_EDIT))) ? WC_ACTION_USER_EDIT : WC_ACTION_USER_VIEW;

	return $out;
}
?>
